package Matricula_Nota;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.DefaultListSelectionModel;
import javax.swing.*;

public class VistaAlumno extends javax.swing.JFrame {

    private Coordinador coordinador;
    private DefaultTableModel mdlAlumnos;

    public VistaAlumno(Coordinador coordinador) {
        initComponents();
        this.coordinador = coordinador;
        mdlAlumnos = (DefaultTableModel) tblAlumnos.getModel();
        tblAlumnos.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
        mostrarAlumnos();
    }

    private void mostrarAlumnos() {
        mdlAlumnos.setRowCount(coordinador.getAlumnos().size());
        // Volcar el contenido de cada entidad Alumno en la tabla
        for (int i = 0; i < coordinador.getAlumnos().size(); i++) {
            Alumno alumno = coordinador.getAlumnos().get(i);
            if (coordinador.getAlumnos().get(i).getEstado() == 1) {
                int c = 1;
                mdlAlumnos.setValueAt(alumno.getCodigo(), i, 0);
                mdlAlumnos.setValueAt(alumno.getNombre(), i, 1);
                mdlAlumnos.setValueAt(alumno.getFecha(), i, 2);
                mdlAlumnos.setValueAt(alumno.getNomApoderado(), i, 3);
                mdlAlumnos.setValueAt(alumno.getDistrito(), i, 4);
                mdlAlumnos.setValueAt(alumno.getDireccion(), i, 5);
                mdlAlumnos.setValueAt(alumno.getTelefono(), i, 6);
                c++;
            }
        }
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlRegistroAlumno = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        btnRegistrarAlumno = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtDni = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jftFechaNaci = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        jcbSexo = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        txtNomApoderado = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        txtOcupacion = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jcbDistrito = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAlumnos = new javax.swing.JTable();
        btnEditarAlumno = new javax.swing.JButton();
        btnEliminarArea = new javax.swing.JButton();
        btnMatriculas = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Mantenimiento de Alumno");

        pnlRegistroAlumno.setBorder(javax.swing.BorderFactory.createTitledBorder("Registro de Alumno"));

        jLabel4.setText("Nombre :");

        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNombreKeyReleased(evt);
            }
        });

        btnRegistrarAlumno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/Save.png"))); // NOI18N
        btnRegistrarAlumno.setToolTipText("Registrar Alumno");
        btnRegistrarAlumno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistrarAlumnoActionPerformed(evt);
            }
        });

        jLabel3.setText("DNI");

        txtDni.setText(" ");
        txtDni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDniKeyPressed(evt);
            }
        });

        jLabel7.setText("Fecha Nacimiento");

        jftFechaNaci.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        jftFechaNaci.setText("12/02/2011");

        jLabel9.setText("Sexo");

        jcbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Masculino", "Femenino" }));

        jLabel13.setText("Telefono");

        txtTelefono.setText(" ");
        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyPressed(evt);
            }
        });

        jLabel25.setText("NombrePadre");

        txtNomApoderado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNomApoderadoKeyPressed(evt);
            }
        });

        jLabel26.setText("Ocupacion Padre");

        txtOcupacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtOcupacionKeyPressed(evt);
            }
        });

        jLabel14.setText("Distrito");

        jcbDistrito.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cercado de Lima", "Ate", "Breña", "Comas", "Chorrillos", "El Agustino", "Jesus Maria", "La Victoria", "La Molina", "Lince", "Miraflores", "Pueblo Libre", "Rimac", "San Isidro", "Independencias", "San Juan de Miraflores", "San Miguel", "Santiago de Surco", "Surquillo", "San Juan de Lurigancho", "Los Olivos", "San Borja", "Villa el Salvador", " ", " " }));

        jLabel11.setText("Direccion");

        txtDireccion.setText(" ");

        javax.swing.GroupLayout pnlRegistroAlumnoLayout = new javax.swing.GroupLayout(pnlRegistroAlumno);
        pnlRegistroAlumno.setLayout(pnlRegistroAlumnoLayout);
        pnlRegistroAlumnoLayout.setHorizontalGroup(
            pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel13)
                    .addComponent(jLabel9)
                    .addComponent(jLabel25)
                    .addComponent(jLabel11))
                .addGap(29, 29, 29)
                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                        .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNomApoderado, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(40, 40, 40)
                        .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                                .addComponent(jLabel26)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnRegistrarAlumno, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(73, 73, 73)
                                .addComponent(txtDni, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                                        .addComponent(jLabel14)
                                        .addGap(57, 57, 57)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jcbDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jftFechaNaci, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(73, Short.MAX_VALUE))
        );
        pnlRegistroAlumnoLayout.setVerticalGroup(
            pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtDni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNomApoderado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel25)))
                    .addGroup(pnlRegistroAlumnoLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jLabel7)
                            .addComponent(jftFechaNaci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(jcbDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnRegistrarAlumno)
                    .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel26))
                    .addGroup(pnlRegistroAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Listado de Alumnos"));

        tblAlumnos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Nombre y Apellido", "F_Nacimiento", "Nom_Apoderado", "Distrito", "Direccion", "Telefono"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblAlumnos);

        btnEditarAlumno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/Edit.png"))); // NOI18N
        btnEditarAlumno.setToolTipText("Editar Alumno");
        btnEditarAlumno.setPreferredSize(new java.awt.Dimension(50, 25));
        btnEditarAlumno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarAlumnoActionPerformed(evt);
            }
        });

        btnEliminarArea.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/Delete.png"))); // NOI18N
        btnEliminarArea.setToolTipText("Eliminar Área");
        btnEliminarArea.setPreferredSize(new java.awt.Dimension(50, 25));
        btnEliminarArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarAreaActionPerformed(evt);
            }
        });

        btnMatriculas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/List.png"))); // NOI18N
        btnMatriculas.setToolTipText("Registrar Matricula");
        btnMatriculas.setPreferredSize(new java.awt.Dimension(50, 25));
        btnMatriculas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMatriculasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 694, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnEditarAlumno, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminarArea, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnMatriculas, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEditarAlumno, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEliminarArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnMatriculas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlRegistroAlumno, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlRegistroAlumno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtDniKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDniKeyPressed
        soloNumeros(evt);
    }//GEN-LAST:event_txtDniKeyPressed

    private void txtNomApoderadoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNomApoderadoKeyPressed
        soloLetras(evt);
    }//GEN-LAST:event_txtNomApoderadoKeyPressed

    private void txtOcupacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOcupacionKeyPressed
        soloLetras(evt);
    }//GEN-LAST:event_txtOcupacionKeyPressed

    private void txtTelefonoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyPressed
        soloNumeros(evt);
    }//GEN-LAST:event_txtTelefonoKeyPressed

    private void txtNombreKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyReleased
        txtNombre.setText(txtNombre.getText().toUpperCase());
}//GEN-LAST:event_txtNombreKeyReleased

    private void btnRegistrarAlumnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarAlumnoActionPerformed
        int p = JOptionPane.showOptionDialog(null, "Deseas Grabar?", "Mensaje", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
        if (p == 0) {
            String nombre, fecha, nomApoderado, distrito, direccion, telelfono, dni, sexo, ocupaApoderado;

            dni = txtDni.getText().trim();
            nombre = txtNombre.getText().trim();
            fecha = jftFechaNaci.getText().trim();

            // edad=Integer.parseInt(txtEdad.getText().trim());
            sexo = jcbSexo.getSelectedItem().toString();
            nomApoderado = txtNomApoderado.getText().trim();
            ocupaApoderado = txtOcupacion.getText().trim();
            distrito = jcbDistrito.getSelectedItem().toString();
            direccion = txtDireccion.getText().trim();
            telelfono = txtTelefono.getText().trim();
            if (!nombre.equals("") || !(dni.equals(""))) {
                try {

                    coordinador.registrarAlumno(dni, nombre, fecha, sexo,
                            nomApoderado, ocupaApoderado, distrito, direccion, telelfono);
                    mostrarAlumnos();

                    Limpiar();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(rootPane, e.getMessage());
                }
            }
        }
}//GEN-LAST:event_btnRegistrarAlumnoActionPerformed

    private void btnEditarAlumnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarAlumnoActionPerformed
        //        int p = JOptionPane.showOptionDialog(null, "Deseas Modificar?", "Mensaje", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
//        if (p == 0) {
//            String codigo, nombre, fecha, nomApoderado, distrito, direccion, telelfono, dni, sexo, ocupaApoderado;
//            codigo = lblCodigo.getText();
//            dni = txtDni.getText().trim();
//            nombre = txtNombre.getText().trim();
//            fecha = jftFechaNaci.getText().trim();
//            sexo = jcbSexo.getSelectedItem().toString();
//            nomApoderado = txtNomApoderado.getText().trim();
//            ocupaApoderado = txtOcupacion.getText().trim();
//            distrito = jcbDistrito.getSelectedItem().toString();
//            direccion = txtDireccion.getText().trim();
//            telelfono = txtTelefono.getText().trim();
//            try {
//                if (!codigo.equals("") && !nombre.equals("")) {
//                    coordinador.ModificaAlumno(codigo, dni, nombre, fecha, sexo, nomApoderado, ocupaApoderado, distrito, direccion, telelfono);
//                    JOptionPane.showMessageDialog(null, "Se Actualizo Correctamente");
//                    mostrarAlumnos();
//                    Habilita(false);
//                    btnEliminarAlumno.setEnabled(false);
//                    btnNuevoAlumno.setEnabled(false);
//                    btnModiAlumno.setEnabled(false);
//                }
//
//            } catch (Exception e) {
//                JOptionPane.showMessageDialog(null, e.getMessage());
//            }
//        }
        int fila = tblAlumnos.getSelectedRow();
        if (fila != -1) {
            Alumno alumno = coordinador.buscarAlumno(mdlAlumnos.getValueAt(fila, 0).toString());
            VistaEdicionAlumno vista = new VistaEdicionAlumno(this, true, coordinador, alumno); //coordinador.buscarAlumno(codAlumno)
            vista.setLocationRelativeTo(this);
            vista.setVisible(true);
            mostrarAlumnos();
        }
}//GEN-LAST:event_btnEditarAlumnoActionPerformed

    private void btnEliminarAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarAreaActionPerformed
        Limpiar();
        int fila = tblAlumnos.getSelectedRow();
        if (fila != -1) {
//            String codigoAlumno = mdlAlumnos.getValueAt(fila, 0).toString();
//            Alumno objAlumno= new  Alumno();
//            objAlumno.setCodigo(codigoAlumno);
//
//            coordinador.EliminarRegistro(objAlumno);
//            mostrarAlumnos();
        }
}//GEN-LAST:event_btnEliminarAreaActionPerformed

    private void btnMatriculasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMatriculasActionPerformed
        int fila = tblAlumnos.getSelectedRow();
        if (fila != -1) {
            String codAlumno = mdlAlumnos.getValueAt(fila, 0).toString();

            Alumno alumno = coordinador.buscarAlumno(codAlumno);
            VistaMatricula vista = new VistaMatricula(this, true, coordinador, alumno); //coordinador.buscarAlumno(codAlumno)
            vista.setLocationRelativeTo(this);
            vista.setVisible(true);
            mostrarAlumnos();
        }       
}//GEN-LAST:event_btnMatriculasActionPerformed

    private void soloNumeros(java.awt.event.KeyEvent evt) {
        int num = evt.getKeyChar();
        switch (num) {
            case 8:
            case 65535:
                break;
            default:
                if (num >= 48 && num <= 57) {
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, "Ingrese Solo Numeros");
                    evt.setKeyCode(8);
                }
        }
    }

    private void soloLetras(java.awt.event.KeyEvent evt) {
        int num = evt.getKeyChar();
        switch (num) {
            case 32:
            case 8:
            case 241:
            case 209:
            case 65535:
                break;
            default:
                if ((num >= 97 && num <= 122) || (num >= 65 && num <= 90)) {
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, "Ingrese Solo Letras");
                    evt.setKeyCode(8);
                }
        }
    }

    private void Habilita(Boolean valor) {
        for (int x = 0; x
                < this.getContentPane().getComponentCount(); x++) {
            if (this.getContentPane().getComponent(x) instanceof JTextField) {
                JTextField textField = (JTextField) this.getContentPane().getComponent(x);
                textField.setEnabled(valor);
            }

        }
    }

    private void Limpiar() {
        for (int x = 0; x < this.getContentPane().getComponentCount(); x++) {
            if (this.getContentPane().getComponent(x) instanceof JPanel) {
                limpiarJPanel((JPanel)this.getContentPane().getComponent(x));
            }
        }
    }

    private void limpiarJPanel(JPanel jPanel) {
        for (int i = 0; i < jPanel.getComponentCount(); i++) {
            if (jPanel.getComponent(i) instanceof JTextField) {
                JTextField textField = (JTextField) jPanel.getComponent(i);
                textField.setText("");
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEditarAlumno;
    private javax.swing.JButton btnEliminarArea;
    private javax.swing.JButton btnMatriculas;
    private javax.swing.JButton btnRegistrarAlumno;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jcbDistrito;
    private javax.swing.JComboBox jcbSexo;
    private javax.swing.JFormattedTextField jftFechaNaci;
    private javax.swing.JPanel pnlRegistroAlumno;
    private javax.swing.JTable tblAlumnos;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtDni;
    private javax.swing.JTextField txtNomApoderado;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtOcupacion;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables
}
